/*
 * @Description:
 * @Author: zhaolei
 * @Date: 2023-04-15 10:28:59
 */
import {
  ADVERTISING_STATUS_LIST,
  ADVERTISING_TYPE,
  ADVERTISING_TYPE_LIST,
  ADVERTISING_POSITION,
  ADVERTISING_POSITION_LIST,
} from '@/const/type';
export const linkOption = (isView) => {
  return {
    submitBtn: false,
    emptyBtn: false,
    labelWidth: 120,
    column: [
      {
        label: '链接类型',
        prop: 'advertisLinkType',
        type: 'select',
        row: true,
        span: 24,
        value: '0',
        disabled: isView,
        dicData: [
          {
            label: '内部页面',
            value: '0',
          },
          {
            label: 'H5链接',
            value: '1',
          },
          // {
          //   label: '无链接',
          //   value: '2',
          // },
        ],
        rules: [
          {
            required: true,
            trigger: 'blur',
            message: '请选择链接类型',
          },
        ],
        control: (val, form) => {
          if (val === '0') {
            return {
              advertisLink: {
                display: false,
              },
              advertisPageId: {
                display: true,
              },
              paramter: {
                display: true,
              },
            };
          } else {
            return {
              advertisLink: {
                display: true,
              },
              advertisPageId: {
                display: false,
              },
              paramter: {
                display: false,
              },
            };
          }
        },
      },
      {
        label: '内部跳转页面',
        prop: 'advertisPageId',
        formslot: true,
        row: true,
        value: '',
        display: false,
        span: 24,
        rules: [
          {
            required: true,
            trigger: 'blur',
            message: '请选择内部跳转页面',
          },
        ],
      },
      {
        label: '',
        prop: 'paramter',
        row: true,
        span: 24,
        formslot: true,
        display: false,
      },
      {
        label: '链接地址',
        prop: 'advertisLink',
        display: false,
        formslot: true,
        span: 24,
        rules: [
          {
            required: true,
            trigger: 'blur',
            message: '请输入链接地址',
          },
        ],
      },
    ],
  };
};
export const tableOption = () => {
  return {
    ...window.$crudMixins.tableOptions,
    addBtn: true,
    editBtn: true,
    delBtn: false,
    menuWidth: 160,
    searchLabelWidth: 110,
    viewBtn: true,
    labelWidth: 130,
    editBtnText: '修改',
    column: [
      {
        label: '广告编号',
        prop: 'id',
        addDisplay: false,
        editDisplay: false,
        width: 100,
      },
      {
        label: '广告名称',
        prop: 'advertisName',
        search: true,
        width: 200,
        rules: [
          {
            required: true,
            message: '请输入广告名称',
          },
          {
            min: 1,
            max: 20,
            message: '长度不能超过20个字符',
            trigger: 'blur',
          },
          // {
          //   pattern: /^[\u4e00-\u9fa5]{1,20}$/,
          //   message: '请输入汉字，最多20个',
          //   trigger: 'blur',
          // },
        ],
      },
      {
        label: '广告类型',
        prop: 'advertisType',
        search: true,
        type: 'select',
        width: 120,
        dicData: ADVERTISING_TYPE_LIST,
        rules: [
          {
            required: true,
            message: '请选择广告类型',
          },
        ],
        control: (val, form) => {
          if (val === ADVERTISING_TYPE.HOME) {
            return {
              imageAddressHome: {
                display: true,
              },
              imageAddressGuide: {
                display: false,
              },
              advertisSeat: {
                display: true,
              },
              countdownFlag: {
                display: false,
              },
              countdownTime: {
                display: false,
              },
              popUpPage: {
                display: false,
              },
              popUpFrequency: {
                display: false,
              },
              limitNewUser: {
                display: false,
              },
            };
          } else if (val === ADVERTISING_TYPE.GUIDE) {
            return {
              countdownFlag: {
                display: true,
              },
              countdownTime: {
                display: true,
              },
              imageAddressHome: {
                display: false,
              },
              imageAddressGuide: {
                display: true,
              },
              advertisSeat: {
                display: false,
              },
              popUpPage: {
                display: false,
              },
              popUpFrequency: {
                display: false,
              },
              limitNewUser: {
                display: false,
              },
            };
          } else if (val === ADVERTISING_TYPE.BULLET) {
            return {
              imageAddressHome: {
                display: true,
              },
              imageAddressGuide: {
                display: false,
              },
              advertisSeat: {
                display: false,
              },
              countdownFlag: {
                display: false,
              },
              countdownTime: {
                display: false,
              },
              popUpPage: {
                display: true,
              },
              popUpFrequency: {
                display: true,
              },
              limitNewUser: {
                display: true,
              },
            };
          } else {
            return {
              popUpPage: {
                display: false,
              },
              popUpFrequency: {
                display: false,
              },
              countdownFlag: {
                display: false,
              },
              countdownTime: {
                display: false,
              },
              imageAddressHome: {
                display: true,
              },
              imageAddressGuide: {
                display: false,
              },
              advertisSeat: {
                display: false,
              },
            };
          }
        },
      },
      {
        label: '广告时间',
        prop: 'advertisingTime',
        width: 180,
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        searchRange: true,
        search: true,
        searchType: 'daterange',
        addDisplay: false,
        editDisplay: false,
        viewDisplay: true,
      },
      {
        label: '广告时间',
        prop: 'advertisingFormTime',
        format: 'yyyy-MM-dd',
        valueFormat: 'yyyy-MM-dd',
        searchRange: true,
        row: true,
        type: 'daterange',
        rules: [
          {
            required: true,
            message: '请选择广告时间',
          },
        ],
        addDisplay: true,
        editDisplay: true,
        viewDisplay: false,
        hide: true,
      },
      {
        label: '是否跳转页面',
        prop: 'jumpFlag',
        type: 'radio',
        slot: true,
        hide: true,
        row: true,
        span: 24,
        addDisplay: true,
        editDisplay: true,
        dicData: [
          {
            label: '不跳转',
            value: '1',
          },
          {
            label: '跳转',
            value: '0',
          },
        ],
        rules: [
          {
            required: true,
            message: '请选择',
          },
        ],
      },
      // {
      //   label: '链接类型',
      //   prop: 'advertisLinkType',
      //   type: 'select',
      //   hide: true,
      //   dicData: [
      //     {
      //       label: '内部页面',
      //       value: '0',
      //     },
      //     {
      //       label: 'H5链接',
      //       value: '1',
      //     },
      //     {
      //       label: '无链接',
      //       value: '2',
      //     },
      //   ],
      //   rules: [
      //     {
      //       required: true,
      //       message: '请选择链接类型',
      //     },
      //   ],
      //   control: (val, form) => {
      //     if (val === '2') {
      //       return {
      //         advertisLink: {
      //           display: false,
      //         },
      //       };
      //     } else {
      //       return {
      //         advertisLink: {
      //           display: true,
      //         },
      //       };
      //     }
      //   },
      // },
      {
        label: '广告链接',
        prop: 'advertisLink',
        addDisplay: false,
        editDisplay: false,
        viewDisplay: false,
        overHidden: true,
        rules: [
          {
            required: true,
            message: '请输入广告链接',
          },
        ],
      },
      {
        label: '状态',
        prop: 'status',
        type: 'select',
        search: true,
        addDisplay: false,
        editDisplay: false,
        dicData: ADVERTISING_STATUS_LIST,
        width: 80,
      },
      {
        label: '广告位置',
        prop: 'advertisSeat',
        search: true,
        type: 'select',
        display: false,
        width: 120,
        dicData: ADVERTISING_POSITION_LIST,
        rules: [
          {
            required: true,
            trigger: 'change',
            message: '请选择广告位置',
          },
        ],
        control: (val, form) => {
          if (val === ADVERTISING_POSITION.INFORMATION_STREAM) {
            return {
              inforMationFlowSeat: {
                display: true,
              },
            };
          } else {
            return {
              inforMationFlowSeat: {
                display: false,
              },
            };
          }
        },
      },
      {
        label: '倒计时长(s)',
        prop: 'countdownFlag',
        type: 'radio',
        hide: true,
        addDisplay: true,
        editDisplay: true,
        display: false,
        span: 12,
        value: '0',
        dicData: [
          {
            label: '不开启',
            value: '1',
          },
          {
            label: '开启',
            value: '0',
          },
        ],
        control: (val, form) => {
          if (val === '1') {
            return {
              countdownTime: {
                display: false,
              },
            };
          } else if (val === '0' && form.advertisType === '1') {
            return {
              countdownTime: {
                display: true,
              },
            };
          } else {
            return {
              countdownTime: {
                display: false,
              },
            };
          }
        },
        rules: [
          {
            required: true,
            trigger: 'blur',
            message: '请选择',
          },
        ],
      },
      {
        label: '时长',
        prop: 'countdownTime',
        type: 'number',
        hide: true,
        display: false,
        addDisplay: true,
        editDisplay: true,
        max: 30,
        min: 3,
        value: 5,
        span: 12,
        rules: [
          {
            pattern: /^[0-9]*[1-9][0-9]*$/,
            message: '时长只能输入正整数',
            trigger: 'blur',
          },
          {
            required: true,
            trigger: 'blur',
            message: '请输入时长',
          },
        ],
      },
      {
        label: '弹框页面',
        prop: 'popUpPage',
        type: 'select',
        hide: true,
        display: false,
        addDisplay: true,
        editDisplay: true,
        span: 12,
        dicData: [
          {
            label: '首页',
            value: '0',
          },
          {
            label: '商城首页',
            value: '1',
          },
        ],
        rules: [
          {
            required: true,
            trigger: 'change',
            message: '请选择弹框页面',
          },
        ],
      },
      {
        label: '弹框频率(天/次)',
        prop: 'popUpFrequency',
        min: 1,
        maxlength: 5,
        display: false,
        addDisplay: true,
        editDisplay: true,
        hide: true,
        rules: [
          {
            required: true,
            trigger: 'blur',
            message: '请输入弹框频率',
          },
          {
            pattern: /^[0-9]*[1-9][0-9]*$/,
            message: '弹框频率只能输入正整数',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '信息流位置',
        prop: 'inforMationFlowSeat',
        span: 12,
        hide: true,
        type: 'number',
        precision: 0,
        min: 0,
        max: 100,
        display: false,
        rules: [
          {
            required: true,
            message: '请输入信息流位置',
          },
        ],
      },
      {
        label: '排序值',
        prop: 'sort',
        hide: true,
        type: 'number',
        precision: 0,
        min: 0,
        max: 100,
        span: 12,
        // row: true,
      },
      {
        label: '限制新用户展示',
        prop: 'limitNewUser',
        type: 'radio',
        span: 12,
        value: '0',
        display: false,
        dicData: [
          {
            label: '是',
            value: '1',
          },
          {
            label: '否',
            value: '0',
          },
        ],
        rules: [
          {
            required: true,
            message: '请勾选限制新用户展示',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '广告图',
        prop: 'imageAddressHome',
        hide: true,
        type: 'upload',
        display: true,
        listType: 'picture-img',
        // listType: 'picture-card',
        fileType: 'img', //img/video/audio
        limit: 1,
        span: 24,
        fileSize: 10 * 1024,
        propsHttp: {
          name: 'hash',
          url: 'key',
        },
        oss: 'qiniu',
        // cropperOption: {
        //   fixed: true,
        //   enlarge: 1,
        //   fixedNumber: [686, 240],
        // },
        // tip: '请上传jpeg/png/jpeg/webp/heic类型的文件，最大可上传10M,选择首页广告图，只能上传1张，选择引导页广告图，可以上传8张',
        tip: '图片格式支持：jpg/png/jpeg/gif。图片大小支持：最大可上传10M。 图片尺寸推荐： 343 * 120px',
        accept: '.jpg,.png,.jpeg,.gif',
        rules: [
          {
            required: true,
            trigger: 'blur',
            message: '请上传广告图',
          },
        ],
      },
      {
        label: '广告图',
        prop: 'imageAddressGuide',
        hide: true,
        type: 'upload',
        listType: 'picture-img',
        fileType: 'img', //img/video/audio
        limit: 1,
        span: 24,
        fileSize: 30 * 1024,
        propsHttp: {
          name: 'hash',
          url: 'key',
        },
        oss: 'qiniu',
        // cropperOption: {
        //   enlarge: 677 / 300,
        //   fixed: true,
        //   fixedNumber: [375 / 677, 1],
        // },
        // tip: '请上传jpeg/png/jpeg/webp/heic类型的文件，最大可上传10M,选择首页广告图，只能上传1张，选择引导页广告图，可以上传8张',
        tip: '图片格式支持：jpg/png/jpeg/gif图片大小支持：最大可上传10M图片尺寸推荐： 750 * 1624px;<br/>视频尺寸推荐：720x1280px 视频格式推荐：MP4 视频大小建议：最大可上传30MB 视频时长建议：不要超过10秒',
        accept: '.jpg,.png,.jpeg,.gif,.mp4',
        rules: [
          {
            required: true,
            message: '请上传广告图',
          },
        ],
      },
    ],
  };
};
